package BasicDataType;

import java.rmi.server.UID;
import java.util.StringTokenizer;

public class CookieType {
	public String sessionID;
	public int change_count;
	public IPP ippPrimary;
	public IPP backup;
	static int sID = 0;
	public CookieType(IPP local){
		UID uid = new UID();
		sessionID = Integer.toString(sID++) + "##" +  local.getString();
		change_count = 0;
	}
	
	public CookieType(IPP local, int change_count, IPP primary, IPP backup){
		UID uid = new UID();
		sessionID = uid.toString() + "_" +  local.getString();
		this.change_count = change_count;
		this.ippPrimary = primary;
		this.backup = backup;
	}
	
	public CookieType(String str){
		StringTokenizer st = new StringTokenizer(str,"_");
		sessionID = st.nextToken();
		change_count = Integer.parseInt(st.nextToken());
		ippPrimary = new IPP(st.nextToken());
		String back = st.nextToken();
		if(back.equals("NULL")){
			backup = null;
		}else{
			backup = new IPP(back);
		}
	}
	
	public String getString(){
		if(backup == null){
			return sessionID + "_" + Integer.toString(change_count) + "_" + ippPrimary.getString() + "_" + "NULL" + "_";
		}
		return sessionID + "_" + Integer.toString(change_count) + "_" + ippPrimary.getString() + "_" + backup.getString() + "_";
	}
	
}
